package projectmanagerapp

import java.util.Date;

class Project {
	
		String name
		String description
		
		String status
		Date dueDate
		
		static belongsTo = [projectManager : User]
		//static hasMany = [teamMembers : User, risks : Risk, requirements : Requirement]
        static hasMany = [teamMembers:Membership, risks : Risk]	
			
				
		def teamMembers() { return memberships.collect{it.user} }
		
		List addToTeamMembers(User user) {
			 Membership.link(user, this) 
			 return teamMembers() 
			 }
		
		List removeFromTeamMembers(User user) {
			 Membership.unlink(user, this) 
			 return teamMembers() 
			 }
		
		String toString() {
			"${name} "
		}
		
		static constraints = {
			name(blank:false)
			description(nullable:true)
			projectManager(blank:false)
			status(blank:false, inList: [" On Hold","In Progress", "Completed"])
			dueDate(nullable: true, min:  new Date())
						
		}
	}
	